<?php
/**
 *
 * @authors Your Name (you@example.org)
 * @date    2018-01-10 17:17:04
 * @version $Id$
 */
namespace app\admin\model;

use Db;
use think\Model;

class AuthRule extends Base
{
    protected $autoWriteTimestamp = true;
    protected $insert             = ['status' => 1, 'module' => 'admin'];
    protected $update             = ['module' => 'admin']; //后台用户

    protected function setNameAttr($value)
    {
        return trim($value);
    }
    protected function setTitleAttr($value)
    {
        return trim($value);
    }

    protected static function init()
    {
        self::beforeDelete(function ($user) {
            //有子栏目 栏目中有文章时，不能删 &&与运算时就是两边同时成立时为真，|| 或时两边一个成立就是真
            if (Db::name('auth_rule')->where('pid', $user->id)->count() > 0) {
                return false;
            }
        });
    }
}
